

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加角色</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${ctx}/layui/layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

  <div class="layui-form" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
      <label class="layui-form-label">角色名称</label>
      <div class="layui-input-block">
         <input type="text" name="rolename" lay-verify="required" placeholder="请输入角色名称" autocomplete="off" class="layui-input" />
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">角色代号</label>
      <div class="layui-input-block">
         <input type="text" name="roleenname" lay-verify="roleenname" placeholder="请输入角色代号" autocomplete="off" class="layui-input" />
      </div>
    </div>
    <div class="layui-form-item layui-hide">
      <button class="layui-btn" lay-submit lay-filter="LAY-user-role-submit" id="LAY-user-role-submit">提交</button>
    </div>
  </div>

  <script src="${ctx}/layui/layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '${ctx}/layui/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
    ,form = layui.form ;
    form.verify({
    	roleenname:function(value,item){
	    	 if(new RegExp("/[\S]+/").test(value)){
			      return '必填项不能为空1';
			 }
	    	 if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
			      return '角色代码不能有特殊字符';
			 }
			 if(!new RegExp("/[\S]+/").test(value)){
			 	var flag =0;
			 	 $.ajax({
		    	 	url:"${ctx}/role/verify",
		    	 	type:"post",
		    	 	data:{"roleenname":value},
		    	 	async: false,
		    	 	success:function(res){
		    	 		if(res.code==200){
		    	 			flag=1;
		    	 		}
		    	 	}
	    		 }) 
	    		 if(flag ==1){
	    		 	return "角色代码已存在";
	    		 }
			 }
    	}
    })
  })
  </script>
</body>
</html>